#ifndef __PACKET_SL651_H__
#define __PACKET_SL651_H__
#include "PacketBase.h"

namespace controller
{
    static const int SL651_BUFFER_MAX = 4100;
#pragma pack(1)
    // 上行
    typedef struct
    {
        uint16_t start;
        uint8_t remote;
        uint8_t local[5];
        uint16_t passwd;
        uint8_t cmd;
        uint16_t len;
        uint8_t stx;
        uint8_t data[SL651_BUFFER_MAX]; // data + end + crc
        int packetlen;                  // 报文长度
    } Sl651UpPacket;

    // 下行
    typedef struct
    {
        uint16_t start;
        uint8_t local[5]; // 遥测站地址
        uint8_t remote;
        uint16_t passwd;
        uint8_t cmd;
        uint16_t len;
        uint8_t stx;                         // 报文起始符
        uint8_t data[SL651_BUFFER_MAX + 20]; // data + end + crc

        int packetlen; // 报文长度
        uint8_t etx;   // etx
        uint64_t rlocal;
        uint16_t rpasswd;
    } Sl651DownPacket;

#pragma pack()

    class PacketSl651 : public PacketBase
    {
        PacketBaseHeader h;

    public:
        Sl651DownPacket p; // 下行包
        Sl651UpPacket u;   // 上行包
        PacketSl651();
        ~PacketSl651();

        // 接收
        void reset_recv();
        PacketBase *on_get(char *data, int size, void *arg = NULL); // 接收数据的处理

        // 组包
        int build();                                    // 多个register
        int to_bytes(char *dataout, void **arg = NULL); // 生成一个字节流的发送包

        // 包打印
        std::string to_string(std::string arg = ""); // 格式化包的输出
    };

};

#endif // ! __PACKET_MODBUS_H__
